<?php

require_once ('Joob/Controller/Router/Interface.php');

class Joob_Controller_Router_Standard implements Joob_Controller_Router_Interface {
	
	public function route($request) {
		$component = $request->getComponentName();
		$module = $request->getModuleName();
		
		require_once 'Joob/Utils/Common.php';
		require_once 'Joob/Registry/Directory.php';
		
		$component = Joob_Utils_Common::convertNameToDirectory($component);
		$module .= "Module";
		$module = Joob_Utils_Common::convertNameToClass($module);
		$modulefile = Joob_Utils_Common::convertNameToClassFile($module);
		$compath = Joob_Registry_Directory::getInstance()->getComponentDirectory($component);
		
		if ($compath == null)	{
			$compath = "Application";
		}
		
		$modfile = $compath."/Module/".$modulefile;
		require_once 'Joob/Loader/Loader.php';
		if (Joob_Loader_Loader::isReadable($modfile))	{
			include $modfile;
			if (class_exists($module))	{
				$moduleObj = new $module;
				return $moduleObj;
			}
		}
		return null;
	}
}

?>